<?php
header('Content-type:text/html; Charset=utf-8');	
include_once('vendor/wxBizDataCrypt.php');

class xcxfunService{
		
	 function fnGetopenInfo($appid,$appsecret,$code,$iv,$encryptedData){
			$grant_type = "authorization_code"; //授权（必填）
			$params = "appid=".$appid."&secret=".$appsecret."&js_code=".$code."&grant_type=".$grant_type;
			$url = "https://api.weixin.qq.com/sns/jscode2session?".$params;
			$res = json_decode($this->httpGet($url),true);
			$sessionKey = $res['session_key'];//取出json里对应的值
			$pc = new WXBizDataCrypt($appid, $sessionKey);
			$errCode = $pc->decryptData($encryptedData, $iv, $data);
			if ($errCode == 0) {
				return json_decode($data,true);
			}else{
				return $errCode;
			}
		}
		
		function httpGet($url) {
			$curl = curl_init();
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($curl, CURLOPT_TIMEOUT, 300);
			curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
			curl_setopt($curl, CURLOPT_URL, $url);
			$res = curl_exec($curl);
			$status = (int)curl_getinfo($curl,CURLINFO_HTTP_CODE);
			if ($status == 404) {
				return $status;
			}
			curl_close($curl);
			return $res;
		  }
		
		
}

?>